package com.hongyue.dey03;

public class NetWindow implements Runnable {
    ticketNum tn = new ticketNum();

    public NetWindow() {
    }

    public NetWindow(ticketNum tn) {
        this.tn = tn;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (tn) {
                if (ticketNum.ticketNum % 2 == 1) {
                    try {
                        tn.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                tn.notify();
                if (ticketNum.ticketNum > 0) {
                    System.out.println("线上官网正在卖出第" + (100 - --ticketNum.ticketNum) + "张票，还剩余" + ticketNum.ticketNum + "张票");
                }
            }
            if (ticketNum.ticketNum == 0) {
                break;
            }
        }
    }
}
